<template>
	<view class="container">
		<tui-navigation-bar @init="initNavigation" :scrollTop="scrollTop" backgroundColor="#fff" color="#333"
			:title="pageTitle" :fontWeight="600" :isShowTitle="true">
			<view class="tui-header" :style="{ marginTop: navBarTop + 'px' }">
				<view class="get-back dy-iconfont icon-qiehuanqizuo" @click="goBack('pages/user/index')"></view>
			</view>
		</tui-navigation-bar>
		<view class="main">
			<view v-if="list.length > 0">
				<view class="header">
					<uv-drop-down ref="dropDown" sign="dropDown_1" :defaultValue="[0,'0','all']" @click="selectMenu">
						<uv-drop-down-item name="operational" type="2" :label="list[operational.activeIndex].time">
						</uv-drop-down-item>
						<uv-drop-down-item name="vip_type" type="1" label='下载链接' :value="0">
						</uv-drop-down-item>
					</uv-drop-down>
					<uv-drop-down-popup @clickItem="clickItem" sign="dropDown_1" @popupChange="change"
						:click-overlay-on-close="true" :currentDropItem="currentDropItem" keyName="time">
					</uv-drop-down-popup>
				</view>
				<view class="form">
					<uv-form labelPosition="left" ref="form">
						<uv-form-item labelWidth="auto" v-for="item in IMData"
							:customStyle="{padding:'24rpx 50rpx 24rpx 24rpx'}" :label="item.name"
							borderBottom>{{item.value}}</uv-form-item>
					</uv-form>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import mp from "@/mixins/mp.js";
	import throttle from '@/uni_modules/uv-ui-tools/libs/function/throttle.js';
	import {
		guid
	} from '@/uni_modules/uv-ui-tools/libs/function/index.js';
	const app = getApp();
	import {
		QueryCodeState,
		ConfirmMyOrder
	} from "@/utils/requset/api.js";
	export default {
		mixins: [mp],
		options: {
			styleIsolation: 'shared'
		}, //解决/deep/不生效**
		components: {},
		data() {
			return {
				navBarOpacity: 0, //标题图标距离顶部距离
				scrollTop: 0.5, //页面滚动高度
				navBarTop: 0, // 导航栏content顶部m-top
				pageTitle: 'IM运营数据', //标题
				modalTitle: '',
				modalContent: '',
				decliningValue: '',
				loading: false,
				orderId: null,
				userStatus: null,
				details: null,
				isT: 0,
				cursorSpacing: 600,
				popupId: 'phone',
				timeId: null,
				headers: {
					image: '',
					title: '',
					brief: '',
				},
				list: [],
				operational: {
					value: 'all',
					activeIndex: 0,
					color: '#333',
					activeColor: '#2878ff',
					child: []
				},
				detailsList: [{
					name: '应用名称',
					value: null,
					id: 'AppName',
				}, {
					name: '应用 SDKAppID',
					value: null,
					id: 'AppId',
				}, {
					name: '所属客户名称',
					value: null,
					id: 'Company',
				}, {
					name: '活跃用户数',
					value: null,
					id: 'ActiveUserNum',
				}, {
					name: '新增注册人数',
					value: null,
					id: 'RegistUserNumOneDay',
				}, {
					name: '累计注册人数',
					value: null,
					id: 'RegistUserNumTotal',
				}, {
					name: '登录次数',
					value: null,
					id: 'LoginTimes',
				}, {
					name: '登录人数',
					value: null,
					id: 'LoginUserNum',
				}, {
					name: '上行消息数',
					value: null,
					id: 'UpMsgNum',
				}, {
					name: '发消息人数',
					value: null,
					id: 'SendMsgUserNum',
				}, {
					name: 'APNs 推送数',
					value: null,
					id: 'APNSMsgNum',
				}, {
					name: '上行消息数（C2C）',
					value: null,
					id: 'C2CUpMsgNum',
				}, {
					name: '下行消息数（C2C）',
					value: null,
					id: 'C2CDownMsgNum',
				}, {
					name: '发消息人数（C2C）',
					value: null,
					id: 'C2CSendMsgUserNum',
				}, {
					name: 'APNs 推送数（C2C）',
					value: null,
					id: 'C2CAPNSMsgNum',
				}, {
					name: '最高在线人数',
					value: null,
					id: 'MaxOnlineNum',
				}, {
					name: '下行消息总数（C2C和群）',
					value: null,
					id: 'DownMsgNum',
				}, {
					name: '关系链对数增加量',
					value: null,
					id: 'ChainIncrease',
				}, {
					name: '关系链对数删除量',
					value: null,
					id: 'ChainDecrease',
				}, {
					name: '上行消息数（群）',
					value: null,
					id: 'GroupUpMsgNum',
				}, {
					name: '下行消息数（群）',
					value: null,
					id: 'GroupDownMsgNum',
				}, {
					name: '发消息人数（群）',
					value: null,
					id: 'GroupSendMsgUserNum',
				}, {
					name: 'APNs 推送数（群）',
					value: null,
					id: 'GroupAPNSMsgNum',
				}, {
					name: '发消息群组数',
					value: null,
					id: 'GroupSendMsgGroupNum',
				}, {
					name: '入群总数',
					value: null,
					id: 'GroupJoinGroupTimes',
				}, {
					name: '退群总数',
					value: null,
					id: 'GroupQuitGroupTimes',
				}],
				resultData: [],
				IMData: null,
				QR_code: null,
				randomContent: null,
				endRequsetFlag: true, // 结束订单的开关 请求未返回结果时无法重复请求
				guidance: '', //提示文字
				UserInfo: null,
				// noticeBar: []
			};
		},
		/**
		 * 计算属性
		 */
		computed: {
			// 获取当前下拉筛选项
			currentDropItem() {
				return this.operational;
			}
		},
		onLoad(options) {
			this.UserInfo = app.globalData.UserInfo
			this.getOrderDetails()
		},
		onShow: function() {},
		/**
		 * 下拉
		 */
		onPullDownRefresh: function() {
			this.getOrderDetails()
		},
		/**
		 * 触底
		 */
		onReachBottom() {},
		/**
		 * 滚动
		 */
		onPageScroll(res) {
			this.scrollTop = res.scrollTop;
		},
		methods: {
			change(e) {},
			clickItem(e) {
				this.operational.activeIndex = e.index;
				this.IMData.forEach((item, index) => {
					this.$set(this.IMData[index], 'value', this.resultData[this.operational.activeIndex][item.id])
				})
			},
			selectMenu(e) {
				const {
					type
				} = e;
				if (type == 1) {
					this.getHistory()
				}
			},
			goLogin() {
				app.doLogin()
			},
			initNavigation(e) {
				this.navBarOpacity = e.opacity;
				this.navBarTop = e.top;
			},
			getHistory() {
				let that = this
				return new Promise((resolve, reject) => {
					let random = that.suijione(true, true, false, 32)
					uni.request({
						url: `https://console.tim.qq.com/v4/open_msg_svc/get_history?sdkappid=1600016041&identifier=${that.UserInfo.authInfo.userId}&usersig=${that.UserInfo.userSig}&random=${random}&contenttype=json`,
						data: {
							"a": "",
							"b": ""
						},
						method: 'POST',
						success(res) {
							console.log(res);
						}
					})
				});
			},
			//获取用户详情
			getOrderDetails() {
				let that = this
				return new Promise((resolve, reject) => {
					let random = that.suijione(true, true, false, 32)
					uni.request({
						url: `https://console.tim.qq.com/v4/openconfigsvr/getappinfo?sdkappid=1600016041&identifier=${that.UserInfo.authInfo.userId}&usersig=${that.UserInfo.userSig}&random=${random}&contenttype=json`,
						data: {
							"a": "",
							"b": ""
						},
						method: 'POST',
						success(res) {
							let result = res.data.Result
							let IMData = that.detailsList
							let list = []
							result.forEach((li, i) => {
								list.push({
									time: li.Date
								})
							})
							IMData.forEach((item, index) => {
								that.$set(IMData[index], 'value', result[0][item.id])
							})
							that.resultData = result
							that.list = list
							that.IMData = IMData
							that.operational.child = list
						}
					})
				});
			},
			getRandom(a, b) {
				var max = a;
				var min = b;
				if (a < b) {
					max = b;
					min = a;
				}
				return parseInt(Math.random() * (max - min)) + min;
			},

			suijione(num, maxA, minlA, fqy) {
				let arr = []
				let arr1 = []
				let arr2 = []
				if (num) {
					for (let m = 0; m <= 9; m++) {
						arr.push(m)
					}
				}
				if (maxA) {
					for (let m = 65; m <= 90; m++) {
						arr1.push(m)
					}
				}
				if (minlA) {
					for (let m = 97; m <= 122; m++) {
						arr2.push(m)
					}
				}
				if (!fqy) {
					console.log('生成位数必传')
				}
				let mergeArr = arr.concat(arr1);
				let mergeArr1 = mergeArr.concat(arr2);
				let _length = mergeArr1.length
				let text = ''
				for (let m = 0; m < fqy; m++) {
					let text1 = ''
					let random = this.getRandom(0, _length)
					if ((mergeArr1[random]) <= 9) {
						text1 = mergeArr1[random]
					} else if ((mergeArr1[random]) > 9) {
						text1 = String.fromCharCode(mergeArr1[random])
					}
					text += text1
				}
				return text
			},


			// 返回上一页
			goBack: function(url) {
				app.beNavigateBack();
			},
		}
	};
</script>
<style lang="scss" scoped>
	.container {
		min-height: 100vh;
		background: #F6F8F7;
		box-sizing: border-box;
		// padding-bottom: 150rpx;

		.tui-header {
			width: 100%;
			position: fixed;
			top: 0;
			padding: 0 42rpx;
			display: flex;
			align-items: center;
			height: 32px;
			transform: translateZ(0);
			z-index: 99999;
			box-sizing: border-box;

			.get-back {
				flex-shrink: 0;
				width: 36rpx;
				height: 36rpx;
				color: #000;
				font-size: 36rpx;
				padding: 2rpx 40rpx 2rpx 2rpx;
			}
		}

		.main {
			box-sizing: border-box;
			// min-height: 100vh;
			// 24rpx
			padding: 176rpx 0 150rpx;
			padding-bottom: calc(constant(safe-area-inset-bottom));
			padding-bottom: calc(env(safe-area-inset-bottom));

			&.main-foot {
				padding-bottom: calc(constant(safe-area-inset-bottom) + 150rpx);
				padding-bottom: calc(env(safe-area-inset-bottom) + 150rpx);
			}


			.call-police {
				width: 100%;
				height: 240rpx;
				border-radius: 20rpx;
				background-image: url("https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/order/call-police.png");
				background-repeat: no-repeat;
				background-size: 100%;
				margin-bottom: 16rpx;
				box-sizing: border-box;
				padding: 28rpx 210rpx 18rpx 28rpx;
				font-size: 22rpx;
				font-weight: 400;
				color: #396DE8;
				line-height: 40rpx;

				.btn-call-police {
					width: 148rpx;
					height: 58rpx;
					background: #FEFFFE;
					border-radius: 20rpx;
					border: 2rpx solid #C5D3F3;
					font-size: 22rpx;
					font-weight: 400;
					color: #2858AB;
					line-height: 58rpx;
					margin-top: 16rpx;
				}
			}

			.content-component {
				box-sizing: border-box;
				padding: 32rpx 24rpx;
				border-radius: 20rpx;

				&.notice-bar {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 16rpx;
					height: 178rpx;
					border-radius: 12rpx;
					padding: 36rpx 28rpx;
					box-sizing: border-box;
					background-image: url("https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/order-header-bg.png");
					background-repeat: no-repeat;
					background-size: 100%;

					.notice-icon {
						width: 85rpx;
						height: 85rpx;
						margin-right: 19rpx;
						flex-shrink: 0;
					}

					.text-box {
						height: 100%;
						display: flex;
						justify-content: space-around;
						flex-direction: column;
						flex: 1;

						.title {
							font-size: 32rpx;
							font-weight: 900;
							color: #1E1F1F;
							line-height: 46rpx;
						}

						.brief {
							font-size: 26rpx;
							font-weight: 400;
							color: #222222;
							line-height: 44rpx;
						}
					}

					.check-cause {
						width: 142rpx;
						height: 58rpx;
						flex-shrink: 0;
						background: #FFFFFF;
						border-radius: 29px;
						border: 2rpx solid #6D9E15;
						backdrop-filter: blur(5rpx);
						font-size: 26rpx;
						font-weight: 900;
						color: #6D9E15;
						line-height: 58rpx;
						text-align: center;
					}
				}

				&.notice-bar-duan {
					height: 102rpx;
					padding: 14rpx 28rpx;

					.text-box {
						justify-content: center;
					}

					.notice-icon {
						width: 74rpx;
						height: 74rpx;
					}
				}

				.order-title {
					font-size: 30rpx;
					font-weight: 900;
					color: #1E1F1F;
					line-height: 44rpx;
					width: 70%;
					display: flex;
					align-items: center;

					.name {
						display: inline-block;
						max-width: 60%;
					}
				}

				.order-list {
					.order-item {
						width: 100%;
						margin-top: 36rpx;
						display: flex;
						justify-content: space-between;
						align-items: flex-start;

						.title {
							font-size: 28rpx;
							font-weight: 400;
							color: #282D2D;
							line-height: 44rpx;
							flex-shrink: 0;
							margin-right: 20rpx;
						}

						.value-box {
							// flex: 1;
							// text-align: right;
							font-size: 28rpx;
							font-weight: 400;
							color: #999B9B;
							line-height: 44rpx;

							.copy {
								margin-left: 12rpx;
								color: #222222;
							}

							&.pengActualPrice {
								color: #282D2D;
								font-weight: 900;
							}

							&.orderPrice,
							&.couponPrice,
							&.actualPrice,
							&.splitAmount {
								color: #FF4664;
								font-weight: 900;
							}

							.value {}
						}
					}
				}

				.btn-contact {
					width: 144rpx;
					height: 58rpx;
					line-height: 58rpx;
					border: 2rpx solid #7B867F;
					color: #999B9B;
					background: #FFFFFF;
					border-radius: 20rpx;
					font-size: 26rpx;
					font-weight: 900;
					color: #999B9B;
					margin-top: 36rpx;
					margin-left: auto;
				}
			}

			.foot-info {
				width: 100%;
				height: 120rpx;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				position: relative;
				box-shadow: 0px 0 19rpx 0px rgba(198, 204, 202, 0.56);
				background: #FFFFFF;
				position: fixed;
				left: 0;
				bottom: 0;
				padding-bottom: constant(safe-area-inset-bottom);
				padding-bottom: env(safe-area-inset-bottom);
				box-sizing: content-box !important;

				.btn-primary {
					text-align: center;
					font-size: 26rpx;
					flex-shrink: 0;
					width: 180rpx;
					height: 78rpx;
					line-height: 78rpx;
					margin-right: 16rpx;
				}

				.btn-custom {
					border: 2rpx solid #7B867F;
					color: #999B9B;
					background: #FFFFFF;
				}

				.btn-default {
					font-weight: 900;
				}
			}

			.make-phone {
				width: 626rpx;
				height: 537rpx;
				background: #FFFFFF;
				background-image: url("https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/order/call_bg.png");
				background-repeat: no-repeat;
				background-size: 100%;
				border-radius: 80rpx;
				box-sizing: border-box;
				padding: 114rpx 56rpx 72rpx;

				.title {
					font-size: 40rpx;
					font-weight: 900;
					color: #FF4664;
					line-height: 56rpx;
					margin-bottom: 38rpx;
				}

				.content {
					font-size: 26rpx;
					font-weight: 400;
					color: #FF4664;
					line-height: 37rpx;
					margin-bottom: 103rpx;
				}

				.btn {
					width: 520rpx;
					height: 80rpx;
					background: #FF4664;
					border-radius: 20rpx;
					font-size: 26rpx;
					font-weight: 900;
					color: #FFFFFF;
					line-height: 80rpx;
					text-align: center;
				}
			}

			.hitePop {
				border-radius: 80rpx;
				background-color: #fff;
				box-sizing: border-box;
				width: 644rpx;
				padding: 40rpx 60rpx 80rpx 60rpx;
				text-align: center;

				.top {
					text-align: right;
					font-size: 0;

					.close {
						width: 26rpx;
					}
				}

				.title {
					font-size: 33rpx;
					font-weight: 900;
					color: #282D2D;
					margin-bottom: 40rpx;
				}

				.content {
					text-align: left;
					font-size: 26rpx;
				}
			}

			.signPop {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.btn-primary {
					text-align: center;
					font-size: 26rpx;
					flex-shrink: 0;
					width: 240rpx;
					height: 80rpx;
					line-height: 80rpx;
				}

				.btn-custom {
					border: 2rpx solid #7B867F;
					color: #999B9B;
					background: #FFFFFF;
				}
			}

			.popup-bottom {
				box-sizing: border-box;
				padding: 48rpx 48rpx 0;
				padding-bottom: 16rpx;
				padding-bottom: 16rpx;
				background: #FFFFFF;
				border-radius: 40rpx 40rpx 0px 0px;

				.header {
					display: flex;
					align-items: center;
					justify-content: space-between;
					box-sizing: border-box;
					padding-bottom: 39rpx;

					.title {
						font-size: 32rpx;
						font-weight: 900;
						color: #282D2D;
						line-height: 45rpx;
					}

					.close {
						font-size: 22rpx
					}
				}

				.dashedBorder {
					border: 2rpx solid #999B9B;
					border-radius: 20rpx;
				}

				.signPop {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 36rpx;

					.btn-primary {
						text-align: center;
						font-size: 32rpx;
						flex-shrink: 0;
						width: calc((100% - 24rpx) / 2);
						height: 102rpx;
						line-height: 102rpx;
					}

					.btn-custom {
						border: 2rpx solid #7B867F;
						color: #999B9B;
						background: #FFFFFF;
					}
				}

			}

			.popup-bottom-code {
				height: 1258rpx;
				border-radius: 80rpx 80rpx 0px 0px;
				box-sizing: border-box;
				background-image: url("https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/order/ewm.png");
				background-repeat: no-repeat;
				background-size: 100%;

				.header {
					display: flex;
					align-items: center;
					justify-content: space-between;
					box-sizing: border-box;
					padding-top: 51rpx;
					padding-right: 56rpx;

					.title {
						font-size: 32rpx;
						font-weight: 900;
						color: #282D2D;
						line-height: 45rpx;
					}

					.close {
						font-size: 22rpx
					}
				}

				.popup-bottom-content {
					display: flex;
					flex-direction: column;
					align-items: center;

					.content1 {
						font-size: 53rpx;
						font-weight: 900;
						color: #1E1F1F;
						line-height: 64rpx;
						margin: 23rpx 0 32rpx 0;
					}

					.content2 {
						font-size: 28rpx;
						font-weight: 400;
						color: #282D2D;
						line-height: 40rpx;
						margin-bottom: 73rpx;
					}

					.code-box-bottom {
						box-sizing: border-box;
						padding: 0 153rpx;
					}

					.code-box-header {
						width: 100%;
						display: flex;
						justify-content: space-between;
						align-items: center;

						.fg {
							width: 2rpx;
							height: 51rpx;
							background: #E3E9E5;
						}

						.code-time {

							.tit {
								font-size: 28rpx;
								font-weight: 400;
								color: #999B9B;
								line-height: 40rpx;
							}


							.data {
								font-size: 30rpx;
								font-weight: 400;
								color: #282D2D;
								line-height: 37rpx;
							}
						}
					}

					.code-box {
						width: 608rpx;
						height: 649rpx;
						background: #FFFFFF;
						box-shadow: 0px 0 12rpx 0px #BFEA72;
						border-radius: 40rpx;
						box-sizing: border-box;
						padding: 47rpx 70rpx 130rpx;
						display: flex;
						flex-direction: column;
						align-items: center;
						margin-bottom: 40rpx;

						.ewm-code {
							width: 315rpx;
							height: 315rpx;
							background-image: url("https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/order/ewm-boder.png");
							background-repeat: no-repeat;
							background-size: 100%;
							margin-top: 69rpx;
							display: flex;
							align-items: center;
							justify-content: center;

							.QR_code {
								width: 267rpx;
								height: 267rpx;
							}
						}
					}
				}
			}

			.popup-succeed {
				// border: 2rpx solid red;
				height: 890rpx;
				width: 626rpx;
				box-sizing: border-box;
				padding-top: 137rpx;
				position: relative;

				.scan-code2 {
					position: absolute;
					top: 0;
					width: 626rpx;
					z-index: 8;
				}

				.close {
					position: absolute;
					top: 18rpx;
					right: 0;
					z-index: 9;
				}

				.content-box {
					width: 100%;
					height: calc(890rpx - 137rpx);
					background: linear-gradient(180deg, #F3FFCA 0%, #FFFFFF 40%, #FFFFFF 100%);
					border-radius: 80rpx;
					position: relative;
					box-sizing: border-box;
					padding: 68rpx 48rpx 0;
					z-index: 7;

					.scan-code1 {
						height: 104rpx;
						width: 104rpx;
						position: absolute;
						left: 50%;
						margin-left: -52rpx;
						top: -52rpx;
					}

					.title {
						font-size: 44rpx;
						font-weight: 900;
						color: #282D2D;
						line-height: 62rpx;
						margin-bottom: 28rpx;
						text-align: center;
					}

					.con {
						font-size: 28rpx;
						font-weight: 400;
						color: #282D2D;
						line-height: 54rpx;

						text {
							vertical-align: middle;
						}

						.btn-over {
							display: inline-block;
							font-size: 26rpx;
							box-sizing: border-box;
							padding: 0 19rpx;
							height: 54rpx;
							line-height: 54rpx;
							background: #565655;
							width: auto;
							vertical-align: middle;
							margin: 0 10rpx;
						}
					}
				}
			}

			.popup-guidance {
				box-sizing: border-box;
				padding-bottom: 100rpx;
				padding-left: 237rpx;

				.remind {
					width: 202rpx;
					height: 118rpx;
					box-sizing: border-box;
					padding: 53rpx 41rpx 28rpx 56rpx;
					background-image: url("https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/order/guidance1.png");
					background-repeat: no-repeat;
					background-size: 100%;
					font-size: 26rpx;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 37rpx;
				}

				.Guidance {
					position: relative;
					width: 505rpx;
					height: 193rpx;
					box-sizing: border-box;
					padding: 59rpx 33rpx 60rpx 51rpx;
					background-image: url("https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/order/guidance2.png");
					background-repeat: no-repeat;
					background-size: 100%;
					font-size: 26rpx;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 37rpx;
					margin-top: 15rpx;

					&::after {
						position: absolute;
						display: block;
						right: 43rpx;
						top: -90rpx;
						content: '';
						width: 150rpx;
						height: 150rpx;
						background: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/empty/rz.png');
						background-repeat: no-repeat;
						background-size: cover;
						z-index: 10;
					}
				}
			}
		}
	}
</style>